#include "MaterialVectorNodeModel.h"

#include "Object/NewObject.h"
#include "MaterialGraph/Pin/MaterialGraphPinModel.h"

void RMaterialVectorNodeModel::FirstTimeInitializeObject()
{
    // Create the output pin
    auto OutputPin3D = NewObject<RMaterialGraphPinModel>(this);
    OutputPin3D->bIsOutput = true;
    OutputPin3D->ValueType = EMaterialGraphValueType::Vector3D;
    Outputs.Add(OutputPin3D);

    auto OutputPin2D = NewObject<RMaterialGraphPinModel>(this);
    OutputPin2D->bIsOutput = true;
    OutputPin2D->ValueType = EMaterialGraphValueType::Vector2D;
    Outputs.Add(OutputPin2D);

    // Create the input pins
    auto XInputPin = NewObject<RMaterialGraphPinModel>(this);
    XInputPin->bIsOutput = false;
    XInputPin->ValueType = EMaterialGraphValueType::Vector1D;
    Inputs.Add(XInputPin);

    auto YInputPin = NewObject<RMaterialGraphPinModel>(this);
    YInputPin->bIsOutput = false;
    YInputPin->ValueType = EMaterialGraphValueType::Vector1D;
    Inputs.Add(YInputPin);

    auto ZInputPin = NewObject<RMaterialGraphPinModel>(this);
    ZInputPin->bIsOutput = false;
    ZInputPin->ValueType = EMaterialGraphValueType::Vector1D;
    Inputs.Add(ZInputPin);
}

CString RMaterialVectorNodeModel::GenerateExpression()
{
    CString Result;
    if(Outputs[0]->HasValidLink())
    {
        Result+=
            U"vec3 "+Outputs[0]->UniqueOutputPinName+U" = vec3("+Inputs[0]->GetValueExpression()+U", "+Inputs[1]->GetValueExpression()+U", "+Inputs[2]->GetValueExpression()+U");\n";
    }

    if(Outputs[1]->HasValidLink())
    {
        Result+=
            U"vec2 "+Outputs[1]->UniqueOutputPinName+U" = vec3("+Inputs[0]->GetValueExpression()+U", "+Inputs[1]->GetValueExpression()+U");\n";
    }

    return Result;
}
